package com.boot.mall.order.web;

import com.alipay.api.AlipayApiException;
import com.boot.mall.order.alipay.AlipayTemplate;
import com.boot.mall.order.alipay.PayVo;
import com.boot.mall.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class AliPayWebController {

    @Autowired
    private AlipayTemplate alipayTemplate;
    @Autowired
    private OrderService orderService;


    @GetMapping(value = "/aliPayOrder",produces = "text/html")
    @ResponseBody
    public String aliPayOrder(@RequestParam("orderSn") String orderSn) throws AlipayApiException {
        PayVo vo = orderService.aliPayForOrder(orderSn);
        String pay = alipayTemplate.pay(vo);
        System.out.println(pay);
        return pay;
    }

}
